<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>已发布上报任务</title>
    <#include "/common/resource.ftl">
    <script type="text/javascript">
        var getSearchParams = function(){
            return {
                title:$("input[name='title']").val() || "",
            };
        }
    </script>
</head>
<body class="bg-gray">

   <div class="ui-operation">
       <div class="ui-buttons">
   		 <div class="layui-btn-group tools">
            <button class="layui-btn layui-btn-normal singleSelected" p="url:'${params.contextPath}/view/icip/datareport/datareport_task_detail.htm',title:'数据上报任务详情',width:'800px',height:'90%'">
				<i class="fa fa-info-circle"></i>任务详情
			</button>
			<button class="layui-btn layui-btn-normal record-button" p="url:'${params.contextPath}/view/icip/datareport/datareport_records.htm',title:'数据上报记录',width:'800px',height:'90%'">
				<i class="fa fa-list"></i>上报记录
			</button>
			
         </div>   
         <div class="ui-searchs">
             <div class="value" style="">
             
                 <input type="text" name="title" placeholder="任务标题">
             </div>
             <input type="button" value="搜索" class="layui-btn layui-btn-danger search-button"/>
         </div>
       </div>
   </div>
   <div class="ui-content" style="padding-left: 10px;padding-right:10px;">
       <table id="datagrid" options="url:'${params.contextPath}/web/task/list.json',params:'getSearchParams',dblClickRow:'showDetail'">
			<thead>
               	<tr>
                   <th data-options="field:'title',width:120">任务标题</th>
                   <th data-options="field:'typeStr',width:120">任务类型</th>
                   <th data-options="field:'priorityStr',width:120,formatter:formatPriority">优先级</th>
                   <th data-options="field:'createName',width:80">发布人</th>
                   <th data-options="field:'orgName',width:100">发布单位</th>
                   <th data-options="field:'createTimeStr',width:100">发布时间</th>
                   <th data-options="field:'deadLineStr',width:100">截止时间</th>
                   <th data-options="field:'_count',width:150,formatter:formatTaskStatistic">任务统计</th>
				</tr>
			</thead>
       </table>
   </div>
   
</body>
<script type="text/javascript">

function formatPriority(val, row) {
    if (row.priority == 1) {
        return '<span class="ui-accept">' + val + '</span>';
    } else if(row.priority == 2){
        return '<span class="ui-warn">' + val + '</span>';
    }else if(row.priority == 3){
    	return '<span class="ui-stop">' + val + '</span>';
    }
    return val;
}

$(function(){
	$(".record-button").click(function(){
		DialogManager.singleSelected2($(this),function(row,params){
			params.url = $.getUrl(params.url, "id", row.id);
			params.url = $.getUrl(params.url, "templateid", row.refId);
			return true;
		});
	});
});

function showDetail(index,row){
	var p ="url:'${params.contextPath}/view/icip/datareport/datareport_task_detail.htm',title:'数据上报任务详情',width:'800px',height:'90%'";
	var params = eval("({" + (p || "") + "})");
    params.url = $.getUrl(params.url, "id", row.id);
	DialogManager.openDialog(JSON.stringify(params).replace("{", "").replace("}", ""));
}

function openReplyDialog(id,refId){
	var p = $(".record-button").attr("p");
    var params = eval("({" + (p || "") + "})");
    params.url = $.getUrl(params.url, "id", id);
	params.url = $.getUrl(params.url, "templateid", refId);
	DialogManager.openDialog(JSON.stringify(params).replace("{", "").replace("}", ""));
}

function formatTaskStatistic(val,row){
	var html = '<span class="ui-accept" style="cursor:pointer;" onclick="openReplyDialog(\''+row.id+'\',\''+row.refId+'\')">应上报['+row.reportCount+']</span>';
	html += '&nbsp;|&nbsp;<span class="ui-accept" style="cursor:pointer;" onclick="openReplyDialog(\''+row.id+'\',\''+row.refId+'\')">已上报['+row.reportedCount+']</span>';
	return html;
}

function formatState(val, row){
	if(val){
		if(val==1){
			return "启用";
		}
		if(val==2){
			return "停用";
		}
	}
}


</script>
</html>
